<?php


namespace application\core;


class Result
{
    /**
     * 成功信息
     * @param $isLog
     * @param mixed $data
     * @param string $msg
     * @param int $code
     * @return array
     */
    public static function success($isLog, $data = "", string $msg = 'Success', int $code = 200): array
    {
        $arr = [
            'code' => $code,
            'msg' => $msg ?? 'Success'
        ];
        if (isset($data)) {
            $arr['data'] = $data;
        }
        if ($isLog === true) {
            Lib::saveLogs($arr, RUN_PATH . "/" . date("Ym"));
        }
        return $arr;
    }

    /**
     * 失败信息
     * @param $isLog
     * @param mixed $data
     * @param string $msg
     * @param int $code
     * @return array
     */
    public static function fail($isLog, $data = "", string $msg = 'Fail', int $code = -200): array
    {
        $arr = [
            'code' => $code,
            'msg' => $msg ?? 'Fail'
        ];
        if (!empty($data)) {
            $arr['data'] = $data;
        }
        if ($isLog === true) {
            Lib::saveLogs($arr, RUN_PATH . "/" . date("Ym"));
        }
        return $arr;
    }
}